

function say() {
    alert("LC:114. 二叉树展开为链表");
}
say();

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {void} Do not return anything, modify root in-place instead.
 */
var flatten = function(root) {
    var arr = [] //11:00-11:10
    dfs(root, arr)
    // console.log('前',arr) // 跟, 左,右
    for(var i = 1; i < arr.length; i++){ //跟.left = null; 根.right = 左
        var pRoot = arr[i - 1]
        var currentNode = arr[i]

        pRoot.left = null
        pRoot.right = currentNode //current包含右边
    }
};

function dfs(root, arr){
    if(root){
        arr.push(root)
        dfs(root.left, arr)
        dfs(root.right, arr)
    }
}